#!/bin/bash
########################################################################
# script name:  check_legato_bkp.sh
# Used for:
# Author:       Martin Dumont
# Contributors:
# Version:      0.1
#
# (date format: date +'%Y/%m/%d')
#
# Date          Version Contributors    Modifications
# ----------    ------- ------------    -------------
# 2011/11/25    0.1     MDUMONT         initial
########################################################################
usage()
{
cat << STOP

usage: $0 [options] [ARG]

This script is used for ....

OPTIONS:
   -h               All hosts (detail output)

Ex.:
$0 -h saprmt01
$0 -h prd
$0 -h dev
$0 -h all

STOP
}
#######################################
# Get parameters
#######################################
while getopts a:h:c OPTION
do
        case $OPTION in
        h)
				HOSTS=$(echo $OPTARG | tr '[A-Z]' '[a-z]' | sed 's/,/ /g')
				;;
        \?)
				usage
				exit 1
				;;
        *)
				usage
				exit 1
				;;
        esac
done
if [ $OPTIND = 1 ]; then usage; exit 1; fi
#######################################
# Variables and environnement
#######################################
BAENV=$(dirname `which $0`)/loadenv.sh
if [ -f $BAENV ]; then . $BAENV; else echo "No env library ($BAENV)"; exit 1; fi
FILE=/tmp/mminfo.$RANDOM
#######################################
# MAIN
#######################################
mminfo -s mtlsvrs040-bkp3 -avot -q 'savetime>last month' -r "client,pool,savetime" |uniq > $FILE.mminfo
for i in `echo $HOSTS | tr ' ' '\n'`
do
	grep $i $FILE.mminfo  | uniq | tail -1 >> $FILE
	grep -q $i $FILE.mminfo || echo $i does not have any backup for the last month
done
cat $FILE && rm $FILE && rm $FILE.mminfo
#######################################
exit 0

